<?php

/**
 * @author 陈韵
 * 海南商免创建订单
 */
namespace App\Service\OrderService\OrderRouteService;
use App\Service\Code\Normal;
use App\Service\OrderService\BaseSupplierRouterService;
use App\Service\VendorClient\Shopshangmian\ShopshangmianApiClient;
use App\Service\TraitService\SupplierRouterOrderTrait;
use App\Model\CommodityModel\SupplierCommodity;

class Shopshangmian extends BaseSupplierRouterService
{
    use SupplierRouterOrderTrait;
    
    /**
     * 订单申报
     * @param array $param
     * @return mixed
     */
    public function orderPay( $param = [] )
    {
       //查询仓库信息
       $orderGoods = current($param['orderGoods']);
       $SupplierCommodity = SupplierCommodity::instance()->where("ID",$orderGoods["supplier_skuid"])->select('SupplierCommodityKey')->first()->toArray();;
       if(empty($SupplierCommodity)){
           return Normal::returnCode(Normal::FAIL,"没有查询到该订单商品的仓库信息，请核实！");
       }
       $param['supplierOrder']["warehouse_no"] = $SupplierCommodity["SupplierCommodityKey"];
       return $this->callSdkApi(ShopshangmianApiClient::class,$param['apiBody'])->createOrder($param);
    }

    /**
     * 订单取消
     * @param array $param
     * @return mixed
     */
    public function orderCancel( $param = [] )
    {
        return Normal::returnCode(Normal::SUC,"处理完成");
    }
    
    /**
     * 订单售后
     * @param array $param
     * @return mixed
     */
    public function orderAfterSale($param = [])
    {
        return $this->callSdkApi(ShopshangmianApiClient::class,$param['apiBody'])->cancelOrder($param);
    }

    /**
     * 商品列表查询接口
     * @param array $param
     * @return mixed
     */
    public function queryGoodsList( $param = [] )
    {
        $res = $this->callSdkApi(ShopshangmianApiClient::class,$param['apiBody'])->{__FUNCTION__}($param['queryBody']);
        if( $res['code'] != Normal::SUC ) {
            return $res;
        }
        return Normal::returnCode(Normal::SUC,"获取成功",[
            'total'     => count($res['data']['list']),
            'list'      => $res['data']['list'],
        ]);
    }
}